package com.ludomancy.gamelib;


public class Accumulator
{
	private long totalTime;
	private long currentTime;
	private boolean paused = false;
	
	public Accumulator(long totalTime)
	{
		this.totalTime = totalTime;
		reset();
	}
	
	public void update()
	{
		if(!paused)
		{
			currentTime -= GameApplet.getFrameTime();
			currentTime = Math.max(0, currentTime);
		}
	}
	
	public float getRatio()
	{
		return 1.0f - Math.min(1.0f,(float)currentTime/(float)totalTime);
	}
	
	public void setPause(boolean pause)
	{
		this.paused = pause;
	}
	
	public boolean isPaused()
	{
		return paused;
	}
	
	public boolean isRunning()
	{
		return !isDone();
	}
		
	public boolean isDone()
	{
		return currentTime == 0;
	}
	
	public void reset()
	{
		currentTime = totalTime;
	}
	
	public void reset(long newTime)
	{
		totalTime = newTime;
		reset();
	}

}
